#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/5/13 18:32
# @Author : 吴敬超
# explain:
import pandas as pd
import threading
import numpy as np
import netCDF4 as nc
import datetime
import csv
import time as ti
import glob
import multiprocessing
import sys

reload(sys)
sys.setdefaultencoding('utf-8')
file_path = 'D:/ehlocean/data/TEMPSALT/B.E.13.B1850C5.ne120_t12.sehires38.003.sunway_02.rtm.h0.0022-02.nc'
outfile = 'BE002202.csv'
nc = nc.Dataset(file_path)
time = nc.variables['time'][:]

lat = nc.variables['lat'][:]
lon = nc.variables['lon'][:]
QCHANR1 = nc.variables['QCHANR'][:]

for tn in range(len(time)):
    for ln in range(len(lat)):
        dit = {}
        dit["time"] = time[tn]
        dit["lat"] = lat[ln]
        dit["lon"] = lon
        dit["qch"] = QCHANR1[tn][ln]
        dataframe = pd.DataFrame(dit)

        dataframe.to_csv(outfile, columns=["time", "lat", "lon", "qch"], header=False, index=False, sep=',',
                         mode="a",
                         line_terminator='\n')
